<template>
  <el-dialog title="标记内容" v-dialogDrag class="tl-dialog" width="70%" :visible.sync="visible" :with-header="false" :modal-append-to-body="true" :append-to-body="true" :destroy-on-close="true" @close="close">
    <el-button type="text" size="medium" @click="openAddDialog('addsignFrom')" icon="el-icon-circle-plus">添加标记</el-button>
    <el-table class="tl-table" ref="mainTable" :data="datas" height="47vh"  @row-dblclick="doRowDbClick" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" @selection-change="doSelectChange" @sort-change="doSortChange" row-key="id" border fit :row-class-name="doChangeRowClassName">
      <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
      <el-table-column prop="operateresult" min-width="300px" label="标记内容"  align="left" header-align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="username" label="创建人" width="100px"  align="center" header-align="center"></el-table-column>
      <el-table-column prop="operatedate" width="200px" label="标记时间" align="center" header-align="center" :formatter="dateFormat"></el-table-column>
      <el-table-column label="操作" width="80px" align="center" v-slot="scope" fixed="right">
        <el-dropdown trigger="hover">
          <el-button type="text" icon="el-icon-s-operation">操作<i class="el-icon-arrow-down el-icon--center"></i></el-button>
          <el-dropdown-menu>
            <el-dropdown-item type="text" icon="el-icon-view" @click.native="openViewDialog('addsignFrom', scope.row.id)">查看</el-dropdown-item>
            <el-dropdown-item type="text" v-if="user.code === scope.row.usercode" icon="el-icon-edit" @click.native="openEditDialog('addsignFrom', scope.row.id)">编辑</el-dropdown-item>
            <el-dropdown-item type="text" v-if="user.code === scope.row.usercode" icon="el-icon-delete" @click.native="deleteSign(scope.row)">删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-table-column>
    </el-table>
    <tl-add-sign ref="addsignFrom" :code = code :name = name @refresh="querySignInfo"></tl-add-sign>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlAddSign from './addSign.vue'
import { filterObjectNull } from '@tapui/utils/util'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_list],
  components: { tlAddSign },
  data() {
    return {
      moduleTitle: '标记',
      url: {
        querySignInfo: '/mpm/project/querySignInfo',
        deleteSign: '/mpm/project/deleteSign',
        querySignPeopleForAll: '/mpm/project/querySignPeopleForAll'
      },
      sourceid: 0,
      sourcetype: '',
      isQueryOnCreated: false,
      visible: false,
      code: '',
      name: ''
    }
  },
  methods: {
    // 删除标记
    deleteSign(row) {
      this.$tap.confirm('确定删除该条标记吗？').then((_) => {
        deleteAction(this.url.deleteSign, { id: row.id }).then((res) => {
          if (res.success) {
            this.$tap.message(res.message, 'success')
            this.datas.splice(this.datas.indexOf(row), 1)
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      })
    },
    // 新增标记
    openAddDialog(editForm) {
      this.$refs[editForm].sourceid = this.sourceid
      this.$refs[editForm].sourcetype = this.sourcetype
      this.$refs[editForm].isAdd = true
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = false
    },
    // 获取该项目标记信息
    querySignInfo() {
      // 获取全部人员
      this.selectForallshare()
      this.loading = true
      let param = {
        sourcetype: this.sourcetype,
        sourceid: this.sourceid,
        operatetype: 'sign',
        usercode: this.user.code,
        sidx: 'operatedate',
        sord: 'desc'
      }
      getAction(this.url.querySignInfo, param).then((res) => {
        if (res.success) {
          this.datas = res.result
          this.loading = false
        } else {
          this.$tap.alert(res.message, 'warning')
          this.loading = false
        }
      })
    },
    doRowDbClick(row, column, event) {
      if (this.user.code === row.usercode) {
        this.openEditDialog('addsignFrom', row.id)
      } else {
        this.openViewDialog('addsignFrom', row.id)
      }
    },
    close() {
      this.$emit('refresh')
    },
    // 获取除当前登陆人员之外的所有经营管理部人员
     selectForallshare() {
      if (this.url.querySignPeopleForAll) {
          getAction(this.url.querySignPeopleForAll).then((res) => {
          if (res.success) {
            this.code = res.result.code
            this.name = res.result.name
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      }
    }
  }
}
</script>
<style scoped lang="scss">
::v-deep .is-scrolling-none + .el-table__fixed-right {
    height: 100% !important;
}
.tl-dialog /deep/ .el-dialog__body {
  padding: 5px 50px 20px 50px !important;
}
</style>
